/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.example.basic;

import org.nudt.jCloud.infrastructure.HomegeneousCluster;
import org.nudt.jCloud.infrastructure.SlotType;
import org.nudt.jCloud.jobScheduler.AFCFSScheduler;
import org.nudt.jCloud.resourceManager.StaticParRM;
import org.nudt.jCloud.resourceScaler.ResourceScaler;
import org.nudt.jCloud.resourceScaler.ThresholdScaler;
import org.nudt.jCloud.simulation.CloudSchedSIM;
import org.nudt.jCloud.simulation.SIMTag;
import org.nudt.jCloud.simulation.User;
import org.nudt.jCloud.simulation.UserBroker;
import org.nudt.jCloud.workload.BatchWLGen;
import org.nudt.jCloud.workload.Workload;
import org.nudt.jCloud.workload.WorkloadGenerator;

public class StaticParExample {

	public static void main(String[] args) {
		CloudSchedSIM.init("StaticParExample");
		HomegeneousCluster homeCluster = new HomegeneousCluster(30, 1000, 4, 4000, 1000, 200000);
		StaticParRM staticParRM = new StaticParRM("StaticParRM", homeCluster);
		staticParRM.addRM(0.4);
		staticParRM.addRM(0.6);
		UserBroker userBroker1 = new UserBroker("UserBroker1", SIMTag.RM_MODE_S);
		ResourceScaler resourceScaler = new ThresholdScaler(5, 0.5);
		SlotType slotType = new SlotType(1, 1000, 250, 0);
		WorkloadGenerator wlGen1 = new BatchWLGen(10, 100, 50, 0.5, 30, slotType);
		Workload wl1 = wlGen1.generate(0);
		userBroker1.init(new AFCFSScheduler("FCFS-Gang"), resourceScaler);
		User user1 = new User("user1", wl1);
		userBroker1.addUser(user1);
		
		UserBroker userBroker2 = new UserBroker("UserBroker2", SIMTag.RM_MODE_S);
		ResourceScaler resourceScaler2 = new ThresholdScaler(5, 0.5);
		WorkloadGenerator wlGen2 = new BatchWLGen(10, 100, 50, 0.5, 30, slotType);
		Workload wl2 = wlGen2.generate(0);
		userBroker2.init(new AFCFSScheduler("FCFS-Gang"), resourceScaler2);
		User user2 = new User("user2", wl2);
		userBroker2.addUser(user2);
		for(int i=0; i<staticParRM.getRMs().size(); ++i){
			CloudSchedSIM.addRM(staticParRM.getRMs().get(i));
		}
		CloudSchedSIM.addUserBroker(userBroker1);
		CloudSchedSIM.addUserBroker(userBroker2);
		CloudSchedSIM.startSimulation();

	}

}
